/**
 * @file    hi_product_scene.c
 * @brief   photo picture.
 *
 * Copyright (c) 2017 Huawei Tech.Co.,Ltd
 *
 * @author    HiMobileCam Reference Develop Team
 * @date      2018/2/2
 * @version   1.0

 */
#include <stdio.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "hi_product_scene_specparam.h"
#include "hi_product_scene_setparam.h"
#include "product_scene_setparam_inner.h"
#include "mpi_vpss.h"
#include "mpi_vi.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

/** \addtogroup     SCENE_CHIP */
/** @{ */  /** <!-- [SCENE_CHIP] */

#define VPSS_3DNR_IEYCNT                 (3)
#define VPSS_3DNR_MDYCNT                 (2)
#define VPSS_3DNR_SFYCNT                 (3)
#define VPSS_3DNR_TFYCNT                 (2)
#define VPSS_3DNR_SFYSFRCNT              (3)
#define VPSS_3DNR_TFYTFRCNT              (6)

HI_S32 PDT_SCENE_SetVI3DNRParam(HI_HANDLE ModHdl, HI_U8 u8Index, HI_PDT_SCENE_PIPE_PARAM_S* pstSceneParam)
{
    #ifdef CONFIG_SCENEAUTO_SUPPORT
    HI_S32 i, j = 0;
    HI_S32 s32Ret = HI_SUCCESS;
    HI_U32 au32Iso[HI_PDT_SCENE_3DNR_MAX_COUNT] = {};
    VI_PIPE_NRX_PARAM_V2_S astNrxParamV2[HI_PDT_SCENE_3DNR_MAX_COUNT] = {};
    VI_PIPE_ATTR_S stViPipeAttr;

    s32Ret = HI_MPI_VI_GetPipeAttr(ModHdl, &stViPipeAttr);
    if (HI_SUCCESS != s32Ret)
    {
        MLOGE("HI_MPI_VI_GetPipeAttr failed.");
        return HI_FAILURE;
    }
    stViPipeAttr.bNrEn = HI_TRUE;
    s32Ret = HI_MPI_VI_SetPipeAttr(ModHdl, &stViPipeAttr);
    if (HI_SUCCESS != s32Ret)
    {
        MLOGE("HI_MPI_VI_SetPipeAttr failed.");
        return HI_FAILURE;
    }

    VI_PIPE_NRX_PARAM_S stNRX = {0};
    stNRX.stNRXParamV2.stNRXAutoV2.u32ParamNum = pstSceneParam[u8Index].stStatic3DNR.u323DNRCount;
    stNRX.stNRXParamV2.stNRXAutoV2.pau32ISO = au32Iso;
    HI_APPCOMM_CHECK_POINTER(stNRX.stNRXParamV2.stNRXAutoV2.pau32ISO, HI_FAILURE);
    stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2 = astNrxParamV2;
    HI_APPCOMM_CHECK_POINTER(stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2, HI_FAILURE);

    stNRX.enNRVersion = VI_NR_V2;
    stNRX.stNRXParamV2.enOptMode = OPERATION_MODE_AUTO;

    s32Ret = HI_MPI_VI_GetPipeNRXParam(ModHdl, &stNRX);
    if (HI_SUCCESS != s32Ret)
    {
        MLOGE("HI_MPI_VI_GetPipeNRXParam failed.");
        return HI_FAILURE;
    }
    memcpy(stNRX.stNRXParamV2.stNRXAutoV2.pau32ISO, pstSceneParam[u8Index].stStatic3DNR.au323DNRIso,
        sizeof(HI_U32) * pstSceneParam[u8Index].stStatic3DNR.u323DNRCount);
    stNRX.stNRXParamV2.stNRXAutoV2.u32ParamNum = pstSceneParam[u8Index].stStatic3DNR.u323DNRCount;

    for (i = 0; i < pstSceneParam[u8Index].stStatic3DNR.u323DNRCount; i++)
    {
        memcpy(&(stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i]), &(stNRX.stNRXParamV2.stNRXManualV2.stNRXParamV2),
            sizeof(VI_PIPE_NRX_PARAM_V2_S));
    }

    for (i = 0; i < stNRX.stNRXParamV2.stNRXAutoV2.u32ParamNum; i++)
    {
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].IEy.IEDZ =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].IEy.IEDZ;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].IEy.IES0 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].IEy.IES0;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].IEy.IES1 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].IEy.IES1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].IEy.IES2 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].IEy.IES2;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].IEy.IES3 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].IEy.IES3;


        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.BWSF4 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.BWSF4;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.DeIdx =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.DeIdx;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.DeRate =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.DeRate;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.JMODE =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.JMODE;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.PBR6 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.PBR6;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SBN6 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SBN6;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SBR1 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SBR1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SBR2 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SBR2;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SBR4 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SBR4;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFN0 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFN0;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFN1 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFN1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFN3 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFN3;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFR =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFR;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFS1 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFS1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFS2 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFS2;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFS4 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFS4;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFT1 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFT1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFT2 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFT2;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFT4 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFT4;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SPN6 =
            (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SPN6;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SRT0 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SRT0;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SRT1 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SRT1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.STH1 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.STH1;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.STH3 =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.STH3;
        stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.TriTh =
            (HI_U16)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.TriTh;
        for (j = 0; j < 3; j++)
        {
            stNRX.stNRXParamV2.stNRXAutoV2.pastNRXParamV2[i].SFy.SFR6[j] =
                (HI_U8)pstSceneParam[u8Index].stStatic3DNR.ast3DNRVIValue[i].SFy.SFR6[j];
        }
    }

    stNRX.enNRVersion = VI_NR_V2;
    stNRX.stNRXParamV2.enOptMode = OPERATION_MODE_AUTO;
    s32Ret = HI_MPI_VI_SetPipeNRXParam(ModHdl, &stNRX);
    if (HI_SUCCESS != s32Ret)
    {
        MLOGE("HI_MPI_VI_SetPipeNRXParam failed.");
        return HI_FAILURE;
    }
#endif
    return HI_SUCCESS;
}

#ifdef CONFIG_SCENEAUTO_SUPPORT
HI_VOID PDT_SCENE_SetVpss3DNR_IEYParam(tV500_VPSS_IEy* vpssIey, HI_SCENE_3DNR_VPSS_IEy* sceneIey)
{
    vpssIey->IEDZ = (HI_U16)sceneIey->IEDZ;
    vpssIey->IES0 = (HI_U8)sceneIey->IES0;
    vpssIey->IES1 = (HI_U8)sceneIey->IES1;
    vpssIey->IES2 = (HI_U8)sceneIey->IES2;
    vpssIey->IES3 = (HI_U8)sceneIey->IES3;
    return;
}

HI_VOID PDT_SCENE_SetVpss3DNR_MDYParam(tV500_VPSS_MDy* vpssMdy, HI_SCENE_3DNR_VPSS_MDy* sceneMdy)
{
    vpssMdy->biPath = (HI_U16)sceneMdy->biPath;
    vpssMdy->MABW0 = (HI_U8)sceneMdy->MABW0;
    vpssMdy->MABW1 = (HI_U8)sceneMdy->MABW1;
    vpssMdy->MABR0 = (HI_U8)sceneMdy->MABR0;
    vpssMdy->MABR1 = (HI_U8)sceneMdy->MABR1;
    vpssMdy->MADZ0 = (HI_U16)sceneMdy->MADZ0;
    vpssMdy->MADZ1 = (HI_U16)sceneMdy->MADZ1;
    vpssMdy->MAI00 = (HI_U16)sceneMdy->MAI00;
    vpssMdy->MAI01 = (HI_U16)sceneMdy->MAI01;
    vpssMdy->MAI02 = (HI_U16)sceneMdy->MAI02;
    vpssMdy->MAI10 = (HI_U16)sceneMdy->MAI10;
    vpssMdy->MAI11 = (HI_U16)sceneMdy->MAI11;
    vpssMdy->MAI12 = (HI_U16)sceneMdy->MAI12;
    vpssMdy->MASW = (HI_U8)sceneMdy->MASW;
    vpssMdy->MATE0 = (HI_U16)sceneMdy->MATE0;
    vpssMdy->MATE1 = (HI_U16)sceneMdy->MATE1;
    vpssMdy->MATH0 = (HI_U16)sceneMdy->MATH0;
    vpssMdy->MATH1 = (HI_U16)sceneMdy->MATH1;
    vpssMdy->MATW = (HI_U16)sceneMdy->MATW;
    return;
}


HI_VOID PDT_SCENE_SetVpss3DNR_SFYParam(tV500_VPSS_SFy* vpssSfy, HI_SCENE_3DNR_VPSS_SFy* sceneSfy)
{
    HI_S32 i = 0;
    vpssSfy->BWSF4 = (HI_U16)sceneSfy->BWSF4;
    vpssSfy->JMODE = (HI_U16)sceneSfy->JMODE;
    vpssSfy->kMode = (HI_U16)sceneSfy->kMode;
    vpssSfy->NRyEn = (HI_U16)sceneSfy->NRyEn;
    vpssSfy->PBR6 = (HI_U8)sceneSfy->PBR6;
    vpssSfy->SBN6 = (HI_U8)sceneSfy->SBN6;
    vpssSfy->SBR1 = (HI_U8)sceneSfy->SBR1;
    vpssSfy->SBR2 = (HI_U8)sceneSfy->SBR2;
    vpssSfy->SBR4 = (HI_U8)sceneSfy->SBR4;
    vpssSfy->SFN0 = (HI_U16)sceneSfy->SFN0;

    vpssSfy->SFN1 = (HI_U16)sceneSfy->SFN1;
    vpssSfy->SFN3 = (HI_U16)sceneSfy->SFN3;
    vpssSfy->SFR = (HI_U8)sceneSfy->SFR;
    vpssSfy->SFS1 = (HI_U8)sceneSfy->SFS1;
    vpssSfy->SFS2 = (HI_U8)sceneSfy->SFS2;
    vpssSfy->SFS4 = (HI_U8)sceneSfy->SFS4;
    vpssSfy->SFT1 = (HI_U8)sceneSfy->SFT1;
    vpssSfy->SFT2 = (HI_U8)sceneSfy->SFT2;
    vpssSfy->SFT4 = (HI_U8)sceneSfy->SFT4;
    vpssSfy->SPN6 = (HI_U8)sceneSfy->SPN6;
    vpssSfy->STH1 = (HI_U16)sceneSfy->STH1;
    vpssSfy->STH3 = (HI_U16)sceneSfy->STH3;
    vpssSfy->TriTh = (HI_U16)sceneSfy->TriTh;

    for (i = 0; i < VPSS_3DNR_SFYSFRCNT; ++i) {
        vpssSfy->SFR6[i] = (HI_U8)sceneSfy->SFR6[i];
    }
    return;
}

HI_VOID PDT_SCENE_SetVpss3DNR_PNRCParam(tV500_VPSS_pNRc* vpssPNrc, HI_SCENE_3DNR_VPSS_pNRc* scenePNrc)
{
    vpssPNrc->CTFS = (HI_U16)scenePNrc->CTFS;
    vpssPNrc->SFC = (HI_U8)scenePNrc->SFC;
    vpssPNrc->TFC = (HI_U16)scenePNrc->TFC;
    return;
}

HI_VOID PDT_SCENE_SetVpss3DNR_RFSParam(tV500_VPSS_RFs* vpssRfs, HI_SCENE_3DNR_VPSS_RFs* sceneRfs)
{
    vpssRfs->advMATH = (HI_U16)sceneRfs->advMATH;
    vpssRfs->RFDZ = (HI_U16)sceneRfs->RFDZ;
    vpssRfs->RFSLP = (HI_U8)sceneRfs->RFSLP;
    vpssRfs->RFUI = (HI_U8)sceneRfs->RFUI;
    return;
}


HI_VOID PDT_SCENE_SetVpss3DNR_TFYParam(tV500_VPSS_TFy* vpssTfy, HI_SCENE_3DNR_VPSS_TFy* sceneTfy)
{
    HI_S32 i = 0;
    vpssTfy->bRef = (HI_U8)sceneTfy->bRef;
    vpssTfy->DZMode0 = (HI_U16)sceneTfy->DZMode0;
    vpssTfy->DZMode1 = (HI_U16)sceneTfy->DZMode1;
    vpssTfy->RFI = (HI_U8)sceneTfy->RFI;
    vpssTfy->SDZ0 = (HI_U16)sceneTfy->SDZ0;
    vpssTfy->SDZ1 = (HI_U16)sceneTfy->SDZ1;
    vpssTfy->STR0 = (HI_U16)sceneTfy->STR0;
    vpssTfy->STR1 = (HI_U16)sceneTfy->STR1;
    vpssTfy->TDX0 = (HI_U16)sceneTfy->TDX0;
    vpssTfy->TDX1 = (HI_U16)sceneTfy->TDX1;

    vpssTfy->TDZ0 = (HI_U16)sceneTfy->TDZ0;
    vpssTfy->TDZ1 = (HI_U16)sceneTfy->TDZ1;
    vpssTfy->tEdge = (HI_U8)sceneTfy->tEdge;
    vpssTfy->TFS0 = (HI_U16)sceneTfy->TFS0;
    vpssTfy->TFS1 = (HI_U16)sceneTfy->TFS1;
    vpssTfy->TSI0 = (HI_U8)sceneTfy->TSI0;
    vpssTfy->TSI1 = (HI_U8)sceneTfy->TSI1;
    vpssTfy->TSS0 = (HI_U8)sceneTfy->TSS0;
    vpssTfy->TSS1 = (HI_U8)sceneTfy->TSS1;

    for (i = 0; i < VPSS_3DNR_TFYTFRCNT; ++i) {
        vpssTfy->TFR0[i] = (HI_U8)sceneTfy->TFR0[i];
        vpssTfy->TFR1[i] = (HI_U8)sceneTfy->TFR1[i];
    }
    return;
}

HI_VOID PDT_SCENE_SetVpss3DNR_NRCSFYParam(tV500_VPSS_SFy* vpssNrcSfy, HI_SCENE_3DNR_VPSS_SFy* sceneNrcSfy)
{
    HI_S32 i = 0;

    vpssNrcSfy->SFS1 = (HI_U8)sceneNrcSfy->SFS1;
    vpssNrcSfy->SFS2 = (HI_U8)sceneNrcSfy->SFS2;
    vpssNrcSfy->SFS4 = (HI_U8)sceneNrcSfy->SFS4;
    vpssNrcSfy->SFT1 = (HI_U8)sceneNrcSfy->SFT1;
    vpssNrcSfy->SFT2 = (HI_U8)sceneNrcSfy->SFT2;
    vpssNrcSfy->SFT4 = (HI_U8)sceneNrcSfy->SFT4;
    vpssNrcSfy->SBR1 = (HI_U8)sceneNrcSfy->SBR1;
    vpssNrcSfy->SBR2 = (HI_U8)sceneNrcSfy->SBR2;
    vpssNrcSfy->SBR4 = (HI_U8)sceneNrcSfy->SBR4;
    vpssNrcSfy->BWSF4 = (HI_U16)sceneNrcSfy->BWSF4;
    vpssNrcSfy->PBR6 = (HI_U8)sceneNrcSfy->PBR6;
    vpssNrcSfy->SBN6 = (HI_U8)sceneNrcSfy->SBN6;
    vpssNrcSfy->SPN6 = (HI_U8)sceneNrcSfy->SPN6;
    vpssNrcSfy->JMODE = (HI_U16)sceneNrcSfy->JMODE;
    vpssNrcSfy->SRT0 = (HI_U16)sceneNrcSfy->SRT0;
    vpssNrcSfy->SRT1 = (HI_U16)sceneNrcSfy->SRT1;
    vpssNrcSfy->DeIdx = (HI_U16)sceneNrcSfy->DeIdx;
    vpssNrcSfy->DeRate = (HI_U8)sceneNrcSfy->DeRate;
    vpssNrcSfy->TriTh = (HI_U16)sceneNrcSfy->TriTh;
    vpssNrcSfy->SFN0 = (HI_U16)sceneNrcSfy->SFN0;
    vpssNrcSfy->SFN1 = (HI_U16)sceneNrcSfy->SFN1;
    vpssNrcSfy->SFN3 = (HI_U16)sceneNrcSfy->SFN3;
    vpssNrcSfy->STH1 = (HI_U16)sceneNrcSfy->STH1;
    vpssNrcSfy->STH3 = (HI_U16)sceneNrcSfy->STH3;
    vpssNrcSfy->SFR = sceneNrcSfy->SFR;
    for (i = 0; i < VPSS_3DNR_SFYSFRCNT; ++i) {
        vpssNrcSfy->SFR6[i] = (HI_U8)sceneNrcSfy->SFR6[i];
    }
    return;
}

HI_VOID PDT_SCENE_SetVpss3DNR_NRCIEYParam(tV500_VPSS_IEy* vpssNrcIey, HI_SCENE_3DNR_VPSS_IEy* sceneNrcIey)
{
    vpssNrcIey->IEDZ = (HI_U16)sceneNrcIey->IEDZ;
    vpssNrcIey->IES0 = (HI_U8)sceneNrcIey->IES0;
    vpssNrcIey->IES1 = (HI_U8)sceneNrcIey->IES1;
    vpssNrcIey->IES2 = (HI_U8)sceneNrcIey->IES2;
    vpssNrcIey->IES3 = (HI_U8)sceneNrcIey->IES3;
    return;
}

HI_S32 PDT_SCENE_SetVPSS3DNRParamAutoMode(HI_HANDLE modHdl, HI_U8 index, HI_PDT_SCENE_PIPE_PARAM_S* sceneParam)
{
    HI_S32 i = 0;
    HI_S32 j = 0;
    HI_S32 ret = HI_SUCCESS;
    HI_U32 iso[HI_PDT_SCENE_3DNR_MAX_COUNT] = {};
    VPSS_NRX_V2_S nrxParam[HI_PDT_SCENE_3DNR_MAX_COUNT] = {};

    VPSS_GRP_NRX_PARAM_S vpssGrpNrx = {0};
    vpssGrpNrx.stNRXParam_V2.stNRXAuto.u32ParamNum = sceneParam[index].stStatic3DNR.u323DNRCount;
    vpssGrpNrx.stNRXParam_V2.stNRXAuto.pau32ISO = iso;
    HI_APPCOMM_CHECK_POINTER(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pau32ISO, HI_FAILURE);
    vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam = nrxParam;
    HI_APPCOMM_CHECK_POINTER(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam, HI_FAILURE);

    vpssGrpNrx.enNRVer = VPSS_NR_V2;
    vpssGrpNrx.stNRXParam_V2.enOptMode = OPERATION_MODE_AUTO;

    ret = HI_MPI_VPSS_GetGrpNRXParam(modHdl, &vpssGrpNrx);
    if (ret != HI_SUCCESS) {
        MLOGE("HI_MPI_VPSS_GetGrpNRXParam failed.");
        return HI_FAILURE;
    }

    for (i = 0; i < sceneParam[index].stStatic3DNR.u323DNRCount; ++i) {
        memcpy(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i]),
             &(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam), sizeof(VPSS_NRX_V2_S));
    }

    memcpy(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pau32ISO,
        sceneParam[index].stStatic3DNR.au323DNRIso, sizeof(HI_U32) * sceneParam[index].stStatic3DNR.u323DNRCount);
    vpssGrpNrx.stNRXParam_V2.stNRXAuto.u32ParamNum = sceneParam[index].stStatic3DNR.u323DNRCount;

    for (i = 0; i < vpssGrpNrx.stNRXParam_V2.stNRXAuto.u32ParamNum; ++i) {
        for (j = 0; j < VPSS_3DNR_IEYCNT; ++j) {
            PDT_SCENE_SetVpss3DNR_IEYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].IEy[j]),
                &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].IEy[j]));
        }

        for (j = 0; j < VPSS_3DNR_MDYCNT; ++j) {
            PDT_SCENE_SetVpss3DNR_MDYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].MDy[j]),
                &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].MDy[j]));
        }

        for (j = 0; j < VPSS_3DNR_SFYCNT; ++j) {
            PDT_SCENE_SetVpss3DNR_SFYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].SFy[j]),
                &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].SFy[j]));
        }

        PDT_SCENE_SetVpss3DNR_PNRCParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].pNRc),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].pNRc));
        PDT_SCENE_SetVpss3DNR_RFSParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].RFs),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].RFs));

        for (j = 0; j < VPSS_3DNR_TFYCNT; ++j) {
            PDT_SCENE_SetVpss3DNR_TFYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].TFy[j]),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].TFy[j]));
        }

        vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].NRc.NRcEn =
                (HI_U8)sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].NRc.NRcEn;
        if (vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].NRc.NRcEn) {
            PDT_SCENE_SetVpss3DNR_NRCSFYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].NRc.SFy),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].NRc.SFy));
            PDT_SCENE_SetVpss3DNR_NRCIEYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXAuto.pastNRXParam[i].NRc.IEy),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[i].NRc.IEy));
        }
    }
    vpssGrpNrx.enNRVer = VPSS_NR_V2;
    vpssGrpNrx.stNRXParam_V2.enOptMode = OPERATION_MODE_AUTO;
    ret = HI_MPI_VPSS_SetGrpNRXParam(modHdl, &vpssGrpNrx);
    if (ret != HI_SUCCESS) {
        MLOGE("HI_MPI_VPSS_SetGrpNRXParam failed.");
        return HI_FAILURE;
    }
    return HI_SUCCESS;
}

HI_S32 PDT_SCENE_SetVPSS3DNRParamManualMode(HI_HANDLE modHdl, HI_U8 index, HI_PDT_SCENE_PIPE_PARAM_S* sceneParam)
{
    HI_S32 i = 0;
    HI_S32 ret = HI_SUCCESS;
    VPSS_GRP_NRX_PARAM_S vpssGrpNrx = {0};
    vpssGrpNrx.enNRVer = VPSS_NR_V2;
    vpssGrpNrx.stNRXParam_V2.enOptMode = OPERATION_MODE_MANUAL;

    ret = HI_MPI_VPSS_GetGrpNRXParam(modHdl, &vpssGrpNrx);
    if (ret != HI_SUCCESS) {
        MLOGE("HI_MPI_VPSS_GetGrpNRXParam failed.");
        return HI_FAILURE;
    }

    for (i = 0; i < VPSS_3DNR_IEYCNT; ++i) {
        PDT_SCENE_SetVpss3DNR_IEYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.IEy[i]),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].IEy[i]));
    }

    for (i = 0; i < VPSS_3DNR_MDYCNT; ++i) {
        PDT_SCENE_SetVpss3DNR_MDYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.MDy[i]),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].MDy[i]));
    }

    for (i = 0; i < VPSS_3DNR_SFYCNT; ++i) {
        PDT_SCENE_SetVpss3DNR_SFYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.SFy[i]),
            &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].SFy[i]));
    }

    PDT_SCENE_SetVpss3DNR_PNRCParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.pNRc),
        &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].pNRc));
    PDT_SCENE_SetVpss3DNR_RFSParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.RFs),
        &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].RFs));

    for (i = 0; i < VPSS_3DNR_TFYCNT; ++i) {
        PDT_SCENE_SetVpss3DNR_TFYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.TFy[i]),
        &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].TFy[i]));
    }

    vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.NRc.NRcEn =
            (HI_U8)sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].NRc.NRcEn;
    if (vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.NRc.NRcEn) {
        PDT_SCENE_SetVpss3DNR_NRCSFYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.NRc.SFy),
        &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].NRc.SFy));
        PDT_SCENE_SetVpss3DNR_NRCIEYParam(&(vpssGrpNrx.stNRXParam_V2.stNRXManual.stNRXParam.NRc.IEy),
        &(sceneParam[index].stStatic3DNR.ast3DNRVPSSValue[0].NRc.IEy));
    }
    vpssGrpNrx.enNRVer = VPSS_NR_V2;
    vpssGrpNrx.stNRXParam_V2.enOptMode = OPERATION_MODE_MANUAL;
    ret = HI_MPI_VPSS_SetGrpNRXParam(modHdl, &vpssGrpNrx);
    if (ret != HI_SUCCESS) {
        MLOGE("HI_MPI_VPSS_SetGrpNRXParam failed.");
        return HI_FAILURE;
    }
    return HI_SUCCESS;

}
#endif


HI_S32 PDT_SCENE_SetVPSS3DNRParam(HI_HANDLE modHdl, HI_U8 index, HI_PDT_SCENE_PIPE_PARAM_S* sceneParam)
{
#ifdef CONFIG_SCENEAUTO_SUPPORT
    HI_S32 ret = HI_SUCCESS;
    if (sceneParam[index].stStatic3DNR.NrMode == 0) {
        ret = PDT_SCENE_SetVPSS3DNRParamAutoMode(modHdl, index, sceneParam);
        if (ret != HI_SUCCESS) {
            MLOGE("PDT_SCENE_SetVPSS3DNRParamAutoMode failed.");
            return HI_FAILURE;
        }
    } else if (sceneParam[index].stStatic3DNR.NrMode == 1) {
        ret = PDT_SCENE_SetVPSS3DNRParamManualMode(modHdl, index, sceneParam);
        if (ret != HI_SUCCESS) {
            MLOGE("PDT_SCENE_SetVPSS3DNRParamManualMode failed.");
            return HI_FAILURE;
        }
    }
#endif
    return HI_SUCCESS;
}

HI_S32 PDT_SCENE_SetStatic3DNR(const HI_PDT_SCENE_MODE_S* pstSceneMode)
{
    HI_S32 i = 0;
    HI_S32 s32Ret = 0;


    HI_PDT_SCENE_PIPE_PARAM_S* pstSceneParam = PDT_SCENE_GetParam();

    for (i = 0; i < HI_PDT_SCENE_PIPE_MAX_NUM; i++)
    {
        if (HI_TRUE != pstSceneMode->astPipeAttr[i].bEnable)
        {
            continue;
        }

        if (pstSceneMode->astPipeAttr[i].bBypassIsp) {
            continue;
        }

        s32Ret = PDT_SCENE_SetVI3DNRParam(pstSceneMode->astPipeAttr[i].VcapPipeHdl,
            pstSceneMode->astPipeAttr[i].u8PipeParamIndex, pstSceneParam);
        HI_APPCOMM_CHECK_RETURN(s32Ret, HI_FAILURE);
    }

    for (i = 0; i < HI_PDT_SCENE_PIPE_MAX_NUM; i++)
    {
        if (HI_TRUE != pstSceneMode->astPipeAttr[i].bEnable)
        {
            continue;
        }

        if (pstSceneMode->astPipeAttr[i].bBypassVpss) {
            continue;
        }

        s32Ret = PDT_SCENE_SetVPSS3DNRParam(pstSceneMode->astPipeAttr[i].VpssHdl,
            pstSceneMode->astPipeAttr[i].u8PipeParamIndex, pstSceneParam);
        HI_APPCOMM_CHECK_RETURN(s32Ret, HI_FAILURE);
    }
    return HI_SUCCESS;
}

/** @}*/  /** <!-- ==== SCENE_CHIP End ====*/

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
